/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#pragma once

#include "State.h"


/**
===============================
Manage current states
Acts as a finite state machine
===============================
*/
class StateMachine
{
public:

    StateMachine(): m_pOwner(NULL), m_pCurrentState(NULL), 
                    m_pPreviousState(NULL) {};

    /** Set the owner of this state machine */
    void SetOwner(IEntity* owner) { m_pOwner = owner; };
    /** Move to another state */
    void SetCurrentState(State* s){  m_pCurrentState = s;}
    /** Revert to a previous state */
    void SetPreviousState(State* s){ m_pPreviousState = s;}

    /** Get the current state */
    State* GetCurrentState() { return m_pCurrentState; };
    /** Retrieve the prev state */
    State* GetPreviousState(){ return m_pPreviousState;};
    /** Change to another state */
	void ChangeState( State* pNewState );
    /** Go back to last state */
    void RevertToPreviousState() { ChangeState(m_pPreviousState); };

    /** check agaisnt state */
    bool IsInState( State* s ) { return s == m_pCurrentState; };
    /** Execute the current state */
	void Update();

    virtual ~StateMachine(void){};

private: 
    //a pointer to the agent that owns this instance
    IEntity*    m_pOwner;
    State*  m_pCurrentState;
    //a record of the last state the agent was in
    State*   m_pPreviousState;
};
